package com.cskaoyan.exception;

import com.cskaoyan.model.vo.ExceptionVO;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.naming.AuthenticationException;

/**
 * @author lxs
 * @date 2022/05/07 11:38
 */
@RestControllerAdvice
public class MallControllerAdvice {

    @ExceptionHandler(NameValidationException.class)
    public ExceptionVO nameValidationException(NameValidationException exception) {
        return ExceptionVO.error(601, exception.getMessage());
    }

    @ExceptionHandler(PwdValidationException.class)
    public ExceptionVO pwdValidationException(PwdValidationException exception) {
        return ExceptionVO.error(602, exception.getMessage());
    }

    @ExceptionHandler(MobileValidationException.class)
    public ExceptionVO mobileValidationException(MobileValidationException exception) {
        return ExceptionVO.error(401, exception.getMessage());
    }

    @ExceptionHandler(QQValidationException.class)
    public ExceptionVO qqValidationException(QQValidationException exception) {
        return ExceptionVO.error(605,exception.getMessage());
    }

    @ExceptionHandler(StockValidationException.class)
    public ExceptionVO stockValidationException(StockValidationException exception) {
        return ExceptionVO.error(711, "库存不足");
    }

    @ExceptionHandler(NickNameValidationException.class)
    public ExceptionVO nickNameValidationException(NickNameValidationException exception){
        return ExceptionVO.error(604,"昵称已被占用");
    }
    @ExceptionHandler(HttpMessageNotReadableException.class)
    public ExceptionVO numberControllerException(HttpMessageNotReadableException exception){
        return ExceptionVO.error(722,"参数格式错误");
    }
    @ExceptionHandler(AuthorizationException.class)
    public ExceptionVO noAuthorizationException(AuthorizationException exception){
        return ExceptionVO.error(733, "你没有权限");
    }
}
